var do_Page = sm("do_Page");
var do_App = sm("do_App");
var nf = sm("do_Notification");
var root = ui("$");
var listdata = mm("do_ListData");
var openHelper = require("helper/open");
//andriod返回键
do_Page.on("back", function() {
  do_App.closePage();
});
var noData = [ {
	"template" : 1
} ];

var headerAout = ui("headerAout");
var listview = ui("listview");
var qqHttp = require("helper/http");
var userUrl = require("url/user");
var listProductData = mm("do_ListData");
var nolistdata = mm("do_ListData");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
  do_App.closePage()
});
var labelTitle = ui(addheader+".labelTitle");
labelTitle.text = "常见问题";

//当前页码
var page = 1;
// 本页面-ajax业务请求url
var httpUrl = userUrl.url.help.page;

//页面装载完成后，开始初始化工作
do_Page.on("loaded", function() {
	laodPage();
});

//邦定数据源
listview.bindItems(listdata);

//刷新数据
function laodPage() {
	page = 1;
	var params = {
		page : page,
	};
	qqHttp.post(userUrl.url.help.page, params, function(data) {
		listview.rebound();
		listdata.removeAll();
		if (data.page) {
			if(data.page.content.length){
				listdata.addData(data.page.content);
			}else{
				listdata.addData(noData);
			}
			listview.refreshItems();// 刷新item数据
		}
	})
}

//刷新数据
function getNextPageData() {
	page++;
	var params = {
		page : page,
	};
	qqHttp.post(userUrl.url.help.page, params, function(data) {
		listview.rebound();
		listdata.addData(data.page.content);
		listview.refreshItems();
	})
}

//下拉列表，刷新数据
listview.on("pull", function(data) {
	if (data.state == 2) {
		laodPage();
	}
});

// 上拉列表，翻页数据
listview.on("push", function(data) {
	if (data.state == 2) {
		getNextPageData();
	}
});

listview.on("touch", function(data, e) {
	var ondata = listdata.getOne(data);
	openHelper.open("source://view/user/help/detail.ui",{
		helpId:ondata.id
	});
});


